package com.wyl.neo4j;

import com.wyl.neo4j.entity.node.Person;
import com.wyl.neo4j.entity.link.Link;
import com.wyl.neo4j.respository.PersonRepository;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@SpringBootTest
class InitPraticeData {

    @Autowired
    private PersonRepository personRepository;

    @Test
    public void testCreate() {
        new Person().setName("");
        Person person1 = new Person().setName("唐僧");
        Person person2 = new Person().setName("孙悟空");
        Person person3 = new Person().setName("猪八戒");
        Person person4 = new Person().setName("沙僧");
        Person person5 = new Person().setName("白龙马");

        // 设置唐僧的徒弟
        person1.setOutgoingPrenticeList(Stream.of(person2, person3, person4, person5)
                .map(item -> new Link().setPerson(item))
                .collect(Collectors.toList()));

        //保存节点数据
        List<Person> personList = new ArrayList<>(Arrays.asList(person1, person2, person3, person4, person5));
        personRepository.saveAll(personList);
    }

    @Test
    public void testfindById() {
        Optional<Person> byId = personRepository.findById(53L);
        System.out.println(byId.orElse(null));
    }

    @Test
    public void testDeleteRelationShip() {
        // 删除所有person节点
        personRepository.deleteAll();
        // 删除所有personRelation关系数据
//        personRelationRepository.deleteAll();
    }

    @Test
    public void testDeletePerson() {
        personRepository.deleteById(1L);
//        personRelationRepository.deleteById(1L);
    }
}



























